#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * DNS Signature Record Structure
 *      Represents a DNS signature (SIG) record.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Net;

namespace Adaptive
{
	namespace Network
	{
		namespace Dns
		{
			/// <summary>
			/// Represents a DNS signature (SIG) record.
			/// </summary>
			public value struct DnsSignatureRecord
			{
			internal:
				/// <summary>
				/// Initializes a new instance of the class from the unmanaged record.
				/// </summary>
				/// <param name="record"> A pointer to a DNS_RECORD structure whose contents are to be copied.</param>
				DnsSignatureRecord(DNS_RECORD* record)
				{
					int count = 0;
					int length = 0;

					if (record == NULL)
					{
						SignerName = String::Empty;
						TypeCovered = 0;
						Algorithm = 0;
						LabelCount = 0;
						OriginalTtl = 0;
						Expiration = 0;
						TimeSigned = 0;
						KeyTag = 0;
						Signature = nullptr;
					}
					else
					{
						SignerName = gcnew String( record->Data.SIG.pNameSigner );
						TypeCovered = record->Data.SIG.wTypeCovered;
						Algorithm = record->Data.SIG.chAlgorithm;
						LabelCount =record->Data.SIG.chLabelCount;
						OriginalTtl = record->Data.SIG.dwOriginalTtl;
						Expiration = record->Data.SIG.dwExpiration;
						TimeSigned = record->Data.SIG.dwTimeSigned;
						KeyTag = record->Data.SIG.wKeyTag;

						length = strlen( (const char *)record->Data.SIG.Signature );
						Signature = gcnew array<Byte>(length);
						for(count = 0; count < length; count++)
							Signature[count] = (Byte)record->Data.SIG.Signature[count];
					}
				}
			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static DnsSignatureRecord()
				{
				}

			public:

				/// <summary>
				/// A string representing the name of the signer that generated the record.
				/// </summary>
				/// <value>
				/// A signer name value or an empty string.
				/// </value>
				String^			SignerName;
				/// <summary>
				/// Type of resource record (RR) covered by the signature
				/// </summary>
				/// <value>
				/// A resource record type value.
				/// </value>
				short			TypeCovered;  
				/// <summary>
				/// Algorithm used with the key specified in the resource record (RR).
				/// </summary>
				/// <value>
				/// The assigned values are shown in the following table:
				///
				///	Value	Meaning 
				/// 1		RSA/MD5 (RFC 2537)
				/// 2		Diffie-Hellman (RFC 2539)
				/// 3		DSA (RFC 2536)
				/// 4		Elliptic curve cryptography.
				/// </value>
				Byte			Algorithm;  
				/// <summary>
				/// Number of labels in the original signature resource record (RR) owner name.
				/// The count does not include the NULL label for the root, nor any initial wildcards.
				/// </summary>
				/// <value>
				/// The number of labels.
				/// </value>
				Byte			LabelCount;  
				/// <summary>
				/// TTL value of the resource record (RR) set signed by the signature RR.
				/// </summary>
				/// <value>
				/// Original time to live value.
				/// </value>
				int				OriginalTtl;  
				/// <summary>
				/// Expiration date, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), excluding 
				/// leap seconds.
				/// </summary>
				/// <value>
				/// The expiration date value.
				/// </value>
				int				Expiration;  
				/// <summary>
				/// Date and time at which the signature becomes valid, expressed in seconds since the beginning of January 1, 
				/// 1970, Greenwich Mean Time (GMT), excluding leap seconds.
				/// </summary>
				/// <value>
				/// The date and time at which the signature becomes valid.
				/// </value>
				int				TimeSigned;  
				/// <summary>
				/// Method used to choose a key that verifies a signature.
				/// </summary>
				/// <value>
				/// Method indicator value.
				/// </value>
				short			KeyTag; 
				/// <summary>
				/// Signature, represented in base 64, formatted as defined in RFC 2535, Appendix A.
				/// </summary>
				/// <value>
				/// A byte array containing the signature, or <b>null</b>.
				/// </value>
				array<Byte>^	Signature;

			};
		}
	}
}